const { Controller } = require('egg');
class BaseController extends Controller {
    success(data) {
        if (data.affectedRows === undefined) {
            if (typeof data == 'string') {
                this.ctx.body = {
                    success: false,
                    message: data,
                };
            } else {
                this.ctx.body = {
                    success: true,
                    data,
                };
            }
            // 获取

        } else {
            // affectedRows 修改 删除 添加
            if (data.affectedRows >= 1) {
                this.ctx.body = {
                    success: true,
                    message: "操作成功",
                };
            } else {
                this.ctx.body = {
                    success: false,
                    message: "操作失败",
                };
            }
        }

    }
    error(message) {
        this.ctx.body = {
            success: false,
            message,
        };
    }
}
module.exports = BaseController;